package com.nopay.dxdwphone.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.nopay.dxdwphone.R;

public class CustomerAdapter extends BaseAdapter {

    private List<String> datas = new ArrayList();
    private LayoutInflater mInflater;

    public CustomerAdapter(Context context) {
        super();
        mInflater = LayoutInflater.from(context);
    }

    public void setDatas(String dataStr) {
        this.datas.clear();
        String[] dataArray = dataStr.split(",");
        Collections.addAll(this.datas, dataArray);
        notifyDataSetChanged();
    }

    public void clear() {
        this.datas.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public String getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_customer, null);
            holder.tv_customer = convertView.findViewById(R.id.tv_customer);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tv_customer.setText(getItem(position));

        return convertView;
    }

    public class ViewHolder {
        private TextView tv_customer;
    }
}
